package data_structures_and_algorithms.list_node;

import common.ListNode;

/**
 * @ClassName Code_0160_getIntersectionNode
 * @Description: 找到相交链表
 *
 * https://leetcode.cn/problems/intersection-of-two-linked-lists/
 * @Author: myl
 * @create_time: 2022/10/28 00:22
 */
public class Code_0160_getIntersectionNode {


    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode curA = headA, curB = headB;
        while (curA != curB){
            curA = curA == null?headB : curA.next;
            curB = curB == null?headA : curB.next;
        }

        return curA;
    }

}
